home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / comm.jar / content / editor / EdSelectProps.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  21.1 KB  |  709 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Selection List Properties Dialog.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Neil Rashbrook.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s): Neil Rashbrook <neil@parkwaycc.co.uk>
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. // Global variables
  38.  
  39. var hasValue;
  40. var oldValue;
  41. var insertNew;
  42. var globalArray;
  43. var selectElement;
  44. var currentObject = null;
  45. var selectedOption = 0;
  46. var selectedOptionCount = 0;
  47.  
  48. // Utility functions
  49.  
  50. function GetObjectForTreeItem(treeItem)
  51. {
  52.   return globalArray[parseInt(treeItem.getAttribute("index"))];
  53. }
  54.  
  55. function InsertBefore(parent, before, after)
  56. {
  57.   var savedObject = currentObject;
  58.   before.parentObject = parent;
  59.   parent.element.insertBefore(before.element, after.element);
  60.   parent.treeChildren.insertBefore(before.treeItem, after.treeItem);
  61.   gDialog.tree.focus();
  62.   selectTreeItem(savedObject.treeItem);
  63.   gDialog.previousButton.disabled = !savedObject.canMoveUp();
  64.   gDialog.nextButton.disabled = !savedObject.canMoveDown();
  65. }
  66.  
  67. function AppendChild(parent, option)
  68. {
  69.   var savedObject = currentObject;
  70.   option.parentObject = parent;
  71.   parent.treeChildren.appendChild(option.treeItem);
  72.   parent.element.appendChild(option.element);
  73.   gDialog.tree.focus();
  74.   selectTreeItem(savedObject.treeItem);
  75.   gDialog.previousButton.disabled = !savedObject.canMoveUp();
  76.   gDialog.nextButton.disabled = !savedObject.canMoveDown();
  77. }
  78.  
  79. function UpdateSelectMultiple()
  80. {
  81.   if (selectedOptionCount > 1)
  82.   {
  83.     gDialog.selectMultiple.checked = true;
  84.     gDialog.selectMultiple.disabled = true;
  85.   }
  86.   else
  87.     gDialog.selectMultiple.disabled = false;
  88. }
  89.  
  90. function createXUL(localName)
  91. {
  92.   return document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", localName);
  93. }
  94.  
  95. // OPTION element wrapper object
  96.  
  97. function optionObject(parent, option)
  98. {
  99.   if (option.hasAttribute("selected"))
  100.     selectedOptionCount++;
  101.   this.globalIndex = globalArray.length;
  102.   globalArray[globalArray.length++] = this;
  103.   this.parentObject = parent;
  104.   this.element = option;
  105.   this.treeItem = createXUL("treeitem");
  106.   this.treeRow = createXUL("treerow");
  107.   this.treeCellText = createXUL("treecell");
  108.   this.treeCellValue = createXUL("treecell");
  109.   this.treeCellSelected = createXUL("treecell");
  110.   this.treeItem.setAttribute("index", this.globalIndex);
  111.   this.treeItem.setAttribute("container", "true");
  112.   this.treeItem.setAttribute("empty", "true");
  113.   this.treeCellText.setAttribute("class", "treecell-indent");
  114.   this.treeCellText.setAttribute("notwisty", "true");
  115.   this.treeCellText.setAttribute("label", option.text);
  116.   if (option.hasAttribute("value"))
  117.     this.treeCellValue.setAttribute("label", option.value);
  118.   else
  119.     this.treeCellValue.setAttribute("label", option.text);
  120.   this.treeCellSelected.setAttribute("properties", "checked-"+option.hasAttribute("selected"));
  121.   this.treeRow.appendChild(this.treeCellText);
  122.   this.treeRow.appendChild(this.treeCellValue);
  123.   this.treeRow.appendChild(this.treeCellSelected);
  124.   this.treeItem.appendChild(this.treeRow);
  125.   parent.treeChildren.appendChild(this.treeItem);
  126.   gDialog.treeItem.setAttribute("open", "true");
  127. }
  128.  
  129. optionObject.prototype.onSpace = function onSpace()
  130. {
  131.   if (this.element.hasAttribute("selected"))
  132.   {
  133.     selectedOptionCount--;
  134.     this.element.removeAttribute("selected");
  135.     this.treeCellSelected.setAttribute("properties", "checked-false");
  136.     gDialog.optionSelected.setAttribute("checked", "false");
  137.     selectedOption = 0;
  138.   }
  139.   else
  140.   {
  141.     if (gDialog.selectMultiple.checked || !globalArray[selectedOption].element.hasAttribute("selected"))
  142.       selectedOptionCount++;
  143.     else
  144.     {
  145.       globalArray[selectedOption].element.removeAttribute("selected");
  146.       globalArray[selectedOption].treeCellSelected.setAttribute("properties", "checked-false");
  147.     }
  148.     this.element.setAttribute("selected", "");
  149.     this.treeCellSelected.setAttribute("properties", "checked-true");
  150.     gDialog.optionSelected.setAttribute("checked", "true");
  151.     selectedOption = this.globalIndex;
  152.   }
  153.   UpdateSelectMultiple();
  154. };
  155.  
  156. optionObject.prototype.onFocus = function onFocus()
  157. {
  158.   gDialog.optionText.value = this.element.text;
  159.   hasValue = this.element.hasAttribute("value");
  160.   oldValue = this.element.value;
  161.   gDialog.optionHasValue.checked = hasValue;
  162.   gDialog.optionValue.value = hasValue ? this.element.value : this.element.text;
  163.   gDialog.optionSelected.checked = this.element.hasAttribute("selected");
  164.   gDialog.optionDisabled.checked = this.element.hasAttribute("disabled");
  165.   gDialog.selectDeck.setAttribute("selectedIndex", "2");
  166. };
  167.  
  168. optionObject.prototype.onBlur = function onBlur()
  169. {
  170.   this.element.text = gDialog.optionText.value;
  171.   if (gDialog.optionHasValue.checked)
  172.     this.element.value = gDialog.optionValue.value;
  173.   else
  174.     this.element.removeAttribute("value");
  175.   if (gDialog.optionSelected.checked)
  176.     this.element.setAttribute("selected", "");
  177.   else
  178.     this.element.removeAttribute("selected");
  179.   if (gDialog.optionDisabled.checked)
  180.     this.element.setAttribute("disabled", "");
  181.   else
  182.     this.element.removeAttribute("disabled");
  183. };
  184.  
  185. optionObject.prototype.canDestroy = function canDestroy(prompt)
  186. {
  187.   return true;
  188. /*return !prompt ||
  189.     ConfirmWithTitle(GetString("DeleteOption"),
  190.                      GetString("DeleteOptionMsg"),
  191.                      GetString("DeleteOption"));*/
  192. };
  193.  
  194. optionObject.prototype.destroy = function destroy()
  195. {
  196.   if (this.element.hasAttribute("selected"))
  197.   {
  198.     selectedOptionCount--;
  199.     UpdateSelectMultiple();
  200.   }
  201.   this.parentObject.removeChild(this);
  202. };
  203.  
  204. optionObject.prototype.canMoveUp = function canMoveUp()
  205. {
  206.   return this.treeItem.previousSibling || this.parentObject != gDialog;
  207. }
  208.  
  209. optionObject.prototype.moveUp = function moveUp()
  210. {
  211.   if (this.treeItem.previousSibling)
  212.     GetObjectForTreeItem(this.treeItem.previousSibling).insertAfter(this);
  213.   else
  214.     InsertBefore(gDialog, this, this.parentObject);
  215. }
  216.  
  217. optionObject.prototype.insertAfter = function insertAfter(option)
  218. {
  219.   InsertBefore(this.parentObject, option, this);
  220. }
  221.  
  222. optionObject.prototype.canMoveDown = function canMoveDown()
  223. {
  224.   return this.treeItem.nextSibling || this.parentObject != gDialog;
  225. }
  226.  
  227. optionObject.prototype.moveDown = function moveDown()
  228. {
  229.   if (this.treeItem.nextSibling)
  230.     GetObjectForTreeItem(this.treeItem.nextSibling).insertBefore(this);
  231.   else if (this.parentObject.treeItem.nextSibling)
  232.     InsertBefore(gDialog, this, GetObjectForTreeItem(this.parentObject.treeItem.nextSibling));
  233.   else
  234.     AppendChild(gDialog, this);
  235. }
  236.  
  237. optionObject.prototype.insertBefore = function insertBefore(option)
  238. {
  239.   InsertBefore(this.parentObject, this, option);
  240. }
  241.  
  242. optionObject.prototype.appendChild = function appendChild(child)
  243. {
  244.   return this.parentObject.appendChild(child);
  245. };
  246.  
  247. // OPTGROUP element wrapper object
  248.  
  249. function optgroupObject(parent, optgroup)
  250. {
  251.   this.globalIndex = globalArray.length;
  252.   globalArray[globalArray.length++] = this;
  253.   this.parentObject = parent;
  254.   this.element = optgroup;
  255.   this.treeItem = createXUL("treeitem");
  256.   this.treeRow = createXUL("treerow");
  257.   this.treeCell = createXUL("treecell");
  258.   this.treeChildren = createXUL("treechildren");
  259.   this.treeItem.setAttribute("index", this.globalIndex);
  260.   this.treeItem.setAttribute("container", "true");
  261.   this.treeItem.setAttribute("empty", "true");
  262.   this.treeItem.setAttribute("open", "true");
  263.   this.treeCell.setAttribute("class", "treecell-indent");
  264.   this.treeCell.setAttribute("notwisty", "true");
  265.   this.treeCell.setAttribute("label", optgroup.label);
  266.   this.treeRow.appendChild(this.treeCell);
  267.   this.treeItem.appendChild(this.treeRow);
  268.   this.treeItem.appendChild(this.treeChildren);
  269.   parent.treeChildren.appendChild(this.treeItem);
  270.   gDialog.treeItem.setAttribute("open", "true");
  271.   for (var child = optgroup.firstChild; child; child = child.nextSibling)
  272.     if (child.tagName == "OPTION")
  273.       new optionObject(this, child);
  274. }
  275.  
  276. optgroupObject.prototype.onSpace = function onSpace()
  277. {
  278. };
  279.  
  280. optgroupObject.prototype.onFocus = function onFocus()
  281. {
  282.   gDialog.optgroupLabel.value = this.element.label;
  283.   gDialog.optgroupDisabled.checked = this.element.disabled;
  284.   gDialog.selectDeck.setAttribute("selectedIndex", "1");
  285. };
  286.  
  287. optgroupObject.prototype.onBlur = function onBlur()
  288. {
  289.   this.element.label = gDialog.optgroupLabel.value;
  290.   this.element.disabled = gDialog.optgroupDisabled.checked;
  291. };
  292.  
  293. optgroupObject.prototype.canDestroy = function canDestroy(prompt)
  294. {
  295.   return !this.element.firstChild;
  296. /*return !this.element.firstChild && (!prompt ||
  297.     ConfirmWithTitle(GetString("DeleteOptGroup"),
  298.                      GetString("DeleteOptGroupMsg"),
  299.                      GetString("DeleteOptGroup")));
  300. */
  301. };
  302.  
  303. optgroupObject.prototype.destroy = function destroy()
  304. {
  305.   gDialog.removeChild(this);
  306. };
  307.  
  308. optgroupObject.prototype.canMoveUp = function canMoveUp()
  309. {
  310.   return this.treeItem.previousSibling;
  311. }
  312.  
  313. optgroupObject.prototype.moveUp = function moveUp()
  314. {
  315.   InsertBefore(this.parentObject, this, GetObjectForTreeItem(this.treeItem.previousSibling));
  316. }
  317.  
  318. optgroupObject.prototype.insertBefore = function insertBefore(option)
  319. {
  320.   if (this.treeChildren.firstChild)
  321.     InsertBefore(this, option, GetObjectForTreeItem(this.treeChildren.firstChild));
  322.   else
  323.     AppendChild(this, option);
  324. }
  325.  
  326. optgroupObject.prototype.canMoveDown = function canMoveDown()
  327. {
  328.   return this.treeItem.nextSibling;
  329. }
  330.  
  331. optgroupObject.prototype.moveDown = function moveDown()
  332. {
  333.   InsertBefore(this.parentObject, GetObjectForTreeItem(this.treeItem.nextSibling), this);
  334. }
  335.  
  336. optgroupObject.prototype.insertAfter = function insertAfter(option)
  337. {
  338.   AppendChild(this, option);
  339. }
  340.  
  341. optgroupObject.prototype.appendChild = function appendChild(child)
  342. {
  343.   this.element.appendChild(child);
  344.   return new optionObject(this, child);
  345. };
  346.  
  347. optgroupObject.prototype.removeChild = function removeChild(child)
  348. {
  349.   this.element.removeChild(child.element);
  350.   this.treeChildren.removeChild(child.treeItem);
  351.   globalArray[child.globalIndex] = null;
  352. };
  353.  
  354. // dialog initialization code
  355.  
  356. function Startup()
  357. {
  358.   if (!InitEditorShell())
  359.     return;
  360.  
  361.   // Get a single selected select element
  362.   var tagName = "select";
  363.   selectElement = editorShell.GetSelectedElement(tagName);
  364.  
  365.   if (selectElement)
  366.     // We found an element and don't need to insert one
  367.     insertNew = false;
  368.   else
  369.   {
  370.     insertNew = true;
  371.  
  372.     // We don't have an element selected,
  373.     //  so create one with default attributes
  374.  
  375.     selectElement = editorShell.CreateElementWithDefaults(tagName);
  376.     if(!selectElement)
  377.     {
  378.       dump("Failed to get selected element or create a new one!\n");
  379.       window.close();
  380.       return;
  381.     }
  382.   }
  383.  
  384.   // SELECT element wrapper object
  385.   gDialog = {
  386.     accept:           document.documentElement.getButton("accept"),
  387.     selectDeck:       document.getElementById("SelectDeck"),
  388.     selectName:       document.getElementById("SelectName"),
  389.     selectSize:       document.getElementById("SelectSize"),
  390.     selectMultiple:   document.getElementById("SelectMultiple"),
  391.     selectDisabled:   document.getElementById("SelectDisabled"),
  392.     selectTabIndex:   document.getElementById("SelectTabIndex"),
  393.     optgroupLabel:    document.getElementById("OptGroupLabel"),
  394.     optgroupDisabled: document.getElementById("OptGroupDisabled"),
  395.     optionText:       document.getElementById("OptionText"),
  396.     optionHasValue:   document.getElementById("OptionHasValue"),
  397.     optionValue:      document.getElementById("OptionValue"),
  398.     optionSelected:   document.getElementById("OptionSelected"),
  399.     optionDisabled:   document.getElementById("OptionDisabled"),
  400.     removeButton:     document.getElementById("RemoveButton"),
  401.     previousButton:   document.getElementById("PreviousButton"),
  402.     nextButton:       document.getElementById("NextButton"),
  403.     tree:             document.getElementById("SelectTree"),
  404.     treeCols:         document.getElementById("SelectCols"),
  405.     treeItem:         document.getElementById("SelectItem"),
  406.     treeCell:         document.getElementById("SelectCell"),
  407.     treeChildren:     document.getElementById("SelectChildren"),
  408.     element:          selectElement.cloneNode(false),
  409.     globalIndex:      0,
  410.     onSpace:          function onSpace() {},
  411.     onFocus:          function onFocus()
  412.     {
  413.       gDialog.selectName.value = this.element.getAttribute("name");
  414.       gDialog.selectSize.value = this.element.getAttribute("size");
  415.       gDialog.selectMultiple.checked = this.element.hasAttribute("multiple");
  416.       gDialog.selectDisabled.checked = this.element.hasAttribute("disabled");
  417.       gDialog.selectTabIndex.value = this.element.getAttribute("tabindex");
  418.       this.selectDeck.setAttribute("selectedIndex", "0");
  419.       onNameInput();
  420.     },
  421.     onBlur:           function onBlur()
  422.     {
  423.       this.element.setAttribute("name", gDialog.selectName.value);
  424.       if (gDialog.selectSize.value)
  425.         this.element.setAttribute("size", gDialog.selectSize.value);
  426.       else
  427.         this.element.removeAttribute("size");
  428.       if (gDialog.selectMultiple.checked)
  429.         this.element.setAttribute("multiple", "");
  430.       else
  431.         this.element.removeAttribute("multiple");
  432.       if (gDialog.selectDisabled.checked)
  433.         this.element.setAttribute("disabled", "");
  434.       else
  435.         this.element.removeAttribute("disabled");
  436.       if (gDialog.selectTabIndex.value)
  437.         this.element.setAttribute("tabindex", gDialog.selectTabIndex.value);
  438.       else
  439.         this.element.removeAttribute("tabindex");
  440.     },
  441.     appendChild:      function appendChild(child)
  442.     {
  443.       if (child.tagName == "OPTION")
  444.       {
  445.         this.element.appendChild(child)
  446.         return new optionObject(this, child);
  447.       }
  448.       if (child.tagName == "OPTGROUP")
  449.       {
  450.         this.element.appendChild(child)
  451.         return new optgroupObject(this, child);
  452.       }
  453.       return null;
  454.     },
  455.     removeChild:      function removeChild(child)
  456.     {
  457.       this.treeChildren.removeChild(child.treeItem);
  458.       globalArray[child.globalIndex] = null;
  459.     },
  460.     canDestroy:       function canDestroy(prompt)
  461.     {
  462.       return false;
  463.     },
  464.     canMoveUp:        function canMoveUp()
  465.     {
  466.       return false;
  467.     },
  468.     canMoveDown:      function canMoveDown()
  469.     {
  470.       return false;
  471.     }
  472.   }
  473.   globalArray = [gDialog];
  474.  
  475.   // Workaround for tree scrollbar bug
  476.   for (var col = gDialog.treeCols.firstChild; col.nextSibling; col = col.nextSibling)
  477.   {
  478.     col.setAttribute("width", col.boxObject.width);
  479.     col.removeAttribute("flex");
  480.   }
  481.  
  482.   // We modify the actual option and optgroup elements so clone them first
  483.   for (var child = selectElement.firstChild; child; child = child.nextSibling)
  484.     gDialog.appendChild(child.cloneNode(true));
  485.  
  486.   UpdateSelectMultiple();
  487.  
  488.   selectTreeItem(gDialog.treeItem);
  489.   onNameInput();
  490.  
  491.   SetTextboxFocus(gDialog.selectName);
  492.  
  493.   SetWindowLocation();
  494. }
  495.  
  496. function InitDialog()
  497. {
  498.   currentObject.onFocus();
  499. }
  500.  
  501. function ValidateData()
  502. {
  503.   currentObject.onBlur();
  504.   return true;
  505. }
  506.  
  507. function onAccept()
  508. {
  509.   // All values are valid - copy to actual element in doc or
  510.   //   element created to insert
  511.   ValidateData();
  512.  
  513.   try {
  514.     // Coalesce into one undo transaction
  515.     editorShell.BeginBatchChanges();
  516.  
  517.     editorShell.CloneAttributes(selectElement, gDialog.element);
  518.  
  519.     if (insertNew)
  520.       // 'true' means delete the selection before inserting
  521.       editorShell.InsertElementAtSelection(selectElement, true);
  522.  
  523.     while (selectElement.firstChild)
  524.       editorShell.DeleteElement(selectElement.firstChild);
  525.  
  526.     var newNodes = gDialog.element.childNodes;
  527.     for (var offset = 0; offset < newNodes.length; offset++)
  528.       editorShell.InsertElement(newNodes[offset], selectElement, offset, true);
  529.   } finally {
  530.     editorShell.EndBatchChanges();
  531.   }
  532.  
  533.   SaveWindowLocation();
  534.  
  535.   return true;
  536. }
  537.  
  538. // Button actions
  539. function AddOption()
  540. {
  541.   var optionElement = editorShell.CreateElementWithDefaults("option");
  542.   var optionObject = currentObject.appendChild(optionElement);
  543.   selectTreeItem(optionObject.treeItem);
  544.   SetTextboxFocus(gDialog.optionText);
  545. }
  546.  
  547. function AddOptGroup()
  548. {
  549.   var optgroupElement = editorShell.CreateElementWithDefaults("optgroup");
  550.   var optgroupObject = gDialog.appendChild(optgroupElement);
  551.   selectTreeItem(optgroupObject.treeItem);
  552.   SetTextboxFocus(gDialog.optgroupLabel);
  553. }
  554.  
  555. function RemoveElement()
  556. {
  557.   if (currentObject.canDestroy(true))
  558.   {
  559.     var selection = currentObject.treeItem;
  560.     selection = selection.nextSibling || selection.previousSibling || selection.parentNode.parentNode;
  561.     currentObject.destroy();
  562.     selectTreeItem(selection);
  563.     gDialog.tree.focus();
  564.   }
  565. }
  566.  
  567. // Event handlers
  568. function onTreeSelect(event)
  569. {
  570.   if (currentObject)
  571.     currentObject.onBlur();
  572.   var selectedItem = gDialog.tree.contentView.getItemAtIndex(gDialog.tree.currentIndex);
  573.   if (selectedItem)
  574.   {
  575.     currentObject = globalArray[parseInt(selectedItem.getAttribute("index"))];
  576.     currentObject.onFocus();
  577.   }
  578.   else
  579.     currentObject = gDialog;
  580.   gDialog.removeButton.disabled = !currentObject.canDestroy(false);
  581.   gDialog.previousButton.disabled = !currentObject.canMoveUp();
  582.   gDialog.nextButton.disabled = !currentObject.canMoveDown();
  583.   globalElement = currentObject.element;
  584. }
  585.  
  586. function onTreeKeyUp(event)
  587. {
  588.   if (event.keyCode == event.DOM_VK_SPACE)
  589.     currentObject.onSpace();
  590. }
  591.  
  592. function onTreeClicked(event)
  593. {
  594.   var row = {}, col = {}, obj = {};
  595.   gDialog.tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj);
  596.   
  597.   if (col.value == "SelectSelCol") {
  598.     var selection = gDialog.tree.contentView.getItemAtIndex(row.value);
  599.     currentObject = globalArray[parseInt(selection.getAttribute("index"))];
  600.     if ("treeCellSelected" in currentObject) {
  601.       selectTreeItem(selection);
  602.       currentObject.onSpace();
  603.     }
  604.   }
  605.   gDialog.tree.focus();
  606. }
  607.  
  608. var timeout = 0;
  609.  
  610. function copyValue(textbox, treecell, delay)
  611. {
  612.   if (timeout) clearTimeout(timeout);
  613.   if (delay)
  614.     timeout = setTimeout(copyValue, 800, textbox, treecell, false);
  615.   else {
  616.     timeout = 0;
  617.     treecell.setAttribute("label", textbox.value);
  618.   }
  619. }
  620.  
  621. function onNameInput()
  622. {
  623.   var disabled = !gDialog.selectName.value;
  624.   if (gDialog.accept.disabled != disabled)
  625.     gDialog.accept.disabled = disabled;
  626.   copyValue(gDialog.selectName, gDialog.treeCell, true);
  627. }
  628.  
  629. function onNameChange()
  630. {
  631.   copyValue(gDialog.selectName, gDialog.treeCell, false);
  632. }
  633.  
  634. function onLabelInput()
  635. {
  636.   copyValue(gDialog.optgroupLabel, currentObject.treeCell, true);
  637. }
  638.  
  639. function onLabelChange()
  640. {
  641.   copyValue(gDialog.optgroupLabel, currentObject.treeCell, false);
  642. }
  643.  
  644. function copyText(delay)
  645. {
  646.   if (timeout) clearTimeout(timeout);
  647.   if (delay)
  648.     timeout = setTimeout(copyText, 800, false);
  649.   else {
  650.     timeout = 0;
  651.     currentObject.treeCellText.setAttribute("label", gDialog.optionText.value);
  652.     if (!hasValue)
  653.     {
  654.       gDialog.optionValue.value = gDialog.optionText.value;
  655.       currentObject.treeCellValue.setAttribute("label", gDialog.optionText.value);
  656.     }
  657.   }
  658. }
  659.  
  660. function onTextInput()
  661. {
  662.   copyText(true);
  663. }
  664.  
  665. function onTextChange()
  666. {
  667.   copyText(false);
  668. }
  669.  
  670. function onValueInput()
  671. {
  672.   gDialog.optionHasValue.checked = hasValue = true;
  673.   oldValue = gDialog.optionValue.value;
  674.   copyValue(gDialog.optionValue, currentObject.treeCellValue, true);
  675. }
  676.  
  677. function onValueChange()
  678. {
  679.   copyValue(gDialog.optionValue, currentObject.treeCellValue, false);
  680. }
  681.  
  682. function onHasValueClick()
  683. {
  684.   hasValue = gDialog.optionHasValue.checked;
  685.   if (hasValue)
  686.   {
  687.     gDialog.optionValue.value = oldValue;
  688.   }
  689.   else
  690.   {
  691.     oldValue = gDialog.optionValue.value;
  692.     gDialog.optionValue.value = gDialog.optionText.value;
  693.   }
  694.   currentObject.treeCellValue.setAttribute("label", gDialog.optionValue.value);
  695. }
  696.  
  697. function onSelectMultipleClick()
  698. {
  699.   if (!gDialog.selectMultiple.checked && selectedOptionCount == 1 && !selectedOption)
  700.     while (!globalArray[selectedOption] || !globalArray[selectedOption].element.hasAttribute("selected"))
  701.       selectedOption++;
  702. }
  703.  
  704. function selectTreeItem(aItem)
  705. {
  706.   var itemIndex = gDialog.tree.contentView.getIndexOfItem(aItem);
  707.   gDialog.tree.treeBoxObject.selection.select(itemIndex);
  708.   gDialog.tree.treeBoxObject.ensureRowIsVisible(itemIndex);
  709. }